package com.hhit.bigscreenbackmanage.service.impl.jjgl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.dao.jjgl.TJjglWgglMxMapper;
import com.hhit.bigscreenbackmanage.dao.jjgl.TJjglWgxmqkDao;
import com.hhit.bigscreenbackmanage.entity.jjgl.TJjglWgxmqk;
import com.hhit.bigscreenbackmanage.service.jjgl.TJjglWgxmqkService;
import com.hhit.bigscreenbackmanage.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * (TJjglWgxmqk)表服务实现类
 *
 * @author makejava
 * @since 2021-07-29 15:38:24
 */
@Service("tJjglWgxmqkService")
public class TJjglWgxmqkServiceImpl implements TJjglWgxmqkService {
    @Resource
    private TJjglWgxmqkDao tJjglWgxmqkDao;

    @Resource
    private TJjglWgglMxMapper tJjglWgglMxMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TJjglWgxmqk queryById(String id) {
        return this.tJjglWgxmqkDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     */
    @Override
    public Map<String,Object> getWgxmqk(JSONObject jsonObject) {
        Map<String,Object> out = new HashMap<>();
        PageUtil page = new PageUtil();
        String pageSize = jsonObject.get("pageSize").toString();
        String pageNo = jsonObject.get("pageNo").toString();
        int count = tJjglWgxmqkDao.queryAllCount(jsonObject);
        page.pageCount=Integer.parseInt(pageSize);// 每页数
        page.init(count,Integer.parseInt(pageNo));//参数1：总行数，参数2：当前页
        jsonObject.put("rowNum",page.getRowNum());
        jsonObject.put("pageCount",page.getPageCount());
        out.put("page",page);
        out.put("list",tJjglWgxmqkDao.queryAll(jsonObject));
        return out;
    }

    /**
     * 新增数据
     *
     * @param tJjglWgxmqk 实例对象
     * @return 实例对象
     */
    @Override
    public TJjglWgxmqk insert(TJjglWgxmqk tJjglWgxmqk) {
        this.tJjglWgxmqkDao.insert(tJjglWgxmqk);
        return tJjglWgxmqk;
    }

    /**
     * 修改数据
     *
     * @param tJjglWgxmqk 实例对象
     * @return 实例对象
     */
    @Override
    public TJjglWgxmqk update(TJjglWgxmqk tJjglWgxmqk) {
        this.tJjglWgxmqkDao.update(tJjglWgxmqk);
        return this.queryById(tJjglWgxmqk.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.tJjglWgxmqkDao.deleteById(id) > 0;
    }

    @Override
    public Map<String, Object> getYlXmWgJz(JSONObject obj) {
        Map<String, Object> out = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        try{
//        TJjglWgxmqk ylXmWgJz = tJjglWgxmqkDao.getYlXmWgJz();
            data.put("wg",tJjglWgglMxMapper.queryWgCount(obj));
            data.put("cqwg",tJjglWgglMxMapper.queryCqwgCount(obj));
            data.put("cqwgjsqbh",tJjglWgglMxMapper.queryCqwgjsqbhCount(obj));
            data.put("bqwg",tJjglWgglMxMapper.queryBqwcwgCount(obj));
            data.put("ljwg",tJjglWgglMxMapper.queryLjwcwgCount(obj));
            out.put("ylXmWgJz",data);
        }catch (Exception e){
            e.printStackTrace();
        }
        return out;
    }

    @Override
    public Map<String, Object> getYlXmWgJzDpList(JSONObject obj) {
        Map<String, Object> out = new HashMap<>();
        List<TJjglWgxmqk> ylXmWgJzDpList = tJjglWgxmqkDao.getYlXmWgJzDpList();
        List<TJjglWgxmqk> collect = ylXmWgJzDpList.stream().filter(item
                -> !"合计".equals(item.getJgdw())).collect(Collectors.toList());
        out.put("list",collect);
        return out;
    }
}